import pymysql

if __name__ == '__main__':
    conn = pymysql.connect(host="127.0.0.1",port=3306,user="root",passwd="root",db="test")
    cursor = conn.cursor()
    sql = "select * from city"
    cursor.execute(sql)
    #获取查询数据
    # data = cursor.fetchone()
    # data = cursor.fetchall()
    data = cursor.fetchmany(2)#查询指定条数
    print(data)
    #释放资源
    cursor.close()
    conn.close()